*** Implementation of the AET implied ratio (Altonji et al. 2005)
*** Results C1 to C6 refer to the 6 columns of Table 6 in Altonji et al. (2005), p. 177. 
*** The implied ratio is given by C6


* y = xb + e (under assumption no treatment effect)
reg $depvar french border $X i.year if (dist >=-40 & dist <= 40)
cap drop gamma
predict gamma if (dist >=-40 & dist <= 40) , xb
cap drop res
predict res if (dist >=-40 & dist <= 40), resid
sum gamma if int_bfr == 1
local g1 = r(mean)
sum gamma if int_bfr == 0
local g2 = r(mean)
sum gamma
local g3 = r(Var)

global C1 = (`g1'-`g2')/`g3'

sum res 
global C2 = r(Var)

global C3 = $C1*$C2

* selection equation
reg int_bfr french border $X i.year if (dist >=-40 & dist <= 40)
cap drop res 
predict res if (dist >=-40 & dist <= 40), resid

sum res 
local C4a = r(Var)

sum int_bfr if (dist >=-40 & dist <= 40)
local C4b = r(Var)

* bias
global C4 = $C3*(`C4b'/`C4a')

reg $depvar french border int_bfr $X i.year if (dist >=-40 & dist <= 40)

global C5 = _b[int_bfr]
global C6 = $C5/$C4

global C1 = round($C1, 0.001)
global C2 = round($C2, 0.001)
global C3 = round($C3, 0.001)
global C4 = round($C4, 0.001)
global C5 = round($C5, 0.001)
global C6 = round($C6, 0.001)
